package es.esp.ut11;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Archivo100Numeros {
	
	public static void lee100Numeros(String ruta) {

		FileInputStream flujoEntrada = null;
		try {
			flujoEntrada = new FileInputStream(ruta);
			int numero;
			
			while((numero = flujoEntrada.read())!=-1){
				System.out.println(numero);
			}

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				flujoEntrada.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}

	public static void escribe100Numeros(String ruta) {

		FileOutputStream flujoSalida = null;
		try {
			flujoSalida = new FileOutputStream(ruta);

			for (int i = 0; i < 100; i++)
				flujoSalida.write(i);

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				flujoSalida.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}

	public static void main(String[] args) {
		escribe100Numeros("100numeros.bin");
		lee100Numeros("100numeros.bin");

		

	}

}
